/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iss.examsys.entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author User
 */
@Entity
@Table(name = "user_group")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Role.findAll", query = "SELECT u FROM Role u"),
    @NamedQuery(name = "Role.findByUserId", query = "SELECT u FROM Role u WHERE u.userGroup.userId = :userId"),
    @NamedQuery(name = "Role.findByGroupName", query = "SELECT u FROM Role u WHERE u.userGroup.groupName = :groupName"),
    @NamedQuery(name = "Role.findByVersion", query = "SELECT u FROM Role u WHERE u.version = :version"),
    @NamedQuery(name = "Role.findByCreatedDate", query = "SELECT u FROM Role u WHERE u.createdDate = :createdDate"),
    @NamedQuery(name = "Role.findByCreatedBy", query = "SELECT u FROM Role u WHERE u.createdBy = :createdBy"),
    @NamedQuery(name = "Role.findByModifiedDate", query = "SELECT u FROM Role u WHERE u.modifiedDate = :modifiedDate"),
    @NamedQuery(name = "Role.findByModifiedBy", query = "SELECT u FROM Role u WHERE u.modifiedBy = :modifiedBy")})
public class Role implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UserGroup userGroup;
    @Column(name = "VERSION")
    private Integer version;
    @Column(name = "CREATED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Column(name = "CREATED_BY")
    private BigInteger createdBy;
    @Column(name = "MODIFIED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedDate;
    @Column(name = "MODIFIED_BY")
    private BigInteger modifiedBy;
    @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;

    public Role() {
    }

    public Role(UserGroup userGroup) {
        this.userGroup = userGroup;
    }

    public Role(String userId, String groupName) {
        this.userGroup = new UserGroup(userId, groupName);
    }

    public UserGroup userGroup() {
        return userGroup;
    }

    public void setUserGroup(UserGroup userGroup) {
        this.userGroup = userGroup;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public BigInteger getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(BigInteger createdBy) {
        this.createdBy = createdBy;
    }

    public Date getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public BigInteger getModifiedBy() {
        return modifiedBy;
    }

    public void setModifiedBy(BigInteger modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userGroup != null ? userGroup.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.userGroup == null && other.userGroup != null) || (this.userGroup != null && !this.userGroup.equals(other.userGroup))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.iss.examsys.entity.UserGroup[ userGroup=" + userGroup + " ]";
    }
    
}
